<template>
  <a-popconfirm
    title="确认删除该设备吗？"
    ok-text="确认"
    cancel-text="取消"
    @confirm="confirm"
    @cancel="cancel"
  >
    <DeleteOutlined
      style="color: red"
      class="cursor-pointer svg-scale"
      title="删除设备"
    />
  </a-popconfirm>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { DeleteOutlined } from "@ant-design/icons-vue";
import { useRoute, useRouter } from "vue-router";
import { isString } from "@/utils/typeGuard";
import { deleteDevice } from "@/controller/Cloud";

export default defineComponent({
  name: "DeleteCloudDeviceConfirm",
  components: {
    DeleteOutlined,
  },
  setup() {
    const route = useRoute();
    const router = useRouter();
    const confirm = async () => {
      if (isString(route.params.id)) {
        await deleteDevice(route.params.id);
        router.push({
          name: "Device",
        });
      }
    };
    const cancel = () => {
      console.log("cancel");
    };
    return { confirm, cancel };
  },
});
</script>

<style scoped lang="scss"></style>
